package com.example.mapper;

import com.example.entity.Speciality;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface SpecialityMapper {

    @Insert("INSERT INTO speciality VALUES(NULL,#{name},#{collegeId})")
    void insert(Speciality speciality);

    @Select("SELECT s.*,c.`name` collegeName FROM speciality s LEFT JOIN college c ON s.college_id=c.id" +
            " WHERE s.name LIKE concat('%',#{name},'%')")
    List<Speciality> selectByName(String name);

    @Select("SELECT s.*,c.`name` collegeName FROM speciality s LEFT JOIN college c ON s.college_id=c.id")
    List<Speciality> selectAll();

    @Update("UPDATE speciality SET name=#{name},college_id=#{collegeId} WHERE id=#{id}")
    void updateById(Speciality speciality);

    @Delete("DELETE FROM speciality WHERE id=#{id}")
    void deleteById(Integer id);
}
